package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.dto.NursingProjectPageDTO;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.ReservationVo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface ReservationMapper {
    /**
     * 查询当天状态的数量（取消……）
     * @param userId
     * @param dayStart
     * @param dayEnd
     * @param status
     * @return
     */
    Integer getCancelledCount(Long userId, LocalDateTime dayStart, LocalDateTime dayEnd, Integer status);

    /**
     * 查询已预约时间段的数量
     * @param nowStart
     * @param endTime
     * @return
     */
    @MapKey("id")
    List<Map<String, Object>> countByTime(LocalDateTime nowStart, LocalDateTime endTime);

    /**
     * 新增预约
     * @param reservation
     */
    void insert(Reservation reservation);

    /**
     * 条件分页
     * @param reservationPageDTO
     * @return
     */
    Page<ReservationVo> pageCondition(NursingProjectPageDTO reservationPageDTO);

    /**
     * 更新预约信息
     * @param reservation
     */
    void update(Reservation reservation);
    @Update("update reservation set status = 2 where status = 0 and time < #{now}")
    void cancelTimeoutReservation(LocalDateTime now);
}
